package com.itheima.mall.controller;

import com.itheima.mall.pojo.HomeBrand;
import com.itheima.mall.service.SmsHomeBrandService;
import com.itheima.mall.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/home/brand")
public class SmsHomeBrandController {

    @Autowired
    private SmsHomeBrandService smsHomeBrandService;


    /**
     * 分页查询推荐品牌
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult> getList(String brandName,Integer pageNum,Integer pageSize, Integer recommendStatus){
        PageResult pageResult = smsHomeBrandService.getList(brandName,pageNum,pageSize,recommendStatus);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 添加首页推荐品牌
     */
    @PostMapping("/create")
    public ResponseEntity<String> createBrand(@RequestBody List<HomeBrand> homeBrandList){
        smsHomeBrandService.createBrand(homeBrandList);
        return ResponseEntity.ok("ok");
    }

    /**
     * 批量删除推荐品牌
     */
    @PostMapping("/delete")
    public ResponseEntity<String> deleteBrand(@RequestParam List<Long> ids){
        smsHomeBrandService.deleteBrand(ids);
        return ResponseEntity.ok("ok");
    }

    /**
     * 批量修改推荐品牌状态
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity<String> updateBrand(@RequestParam List<Long> ids, Integer recommendStatus){
        smsHomeBrandService.updateBrand(ids,recommendStatus);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改推荐品牌排序
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity<String> updateSort(@PathVariable Long id, Integer sort){
        smsHomeBrandService.updateSort(id,sort);
        return ResponseEntity.ok("ok");
    }


}
